<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "order-order",
});


import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import { reactive } from "vue";
import StudentSelect from "/$/student/components/student-select.vue";
import ProductSelect from "/$/product/components/product-select.vue";

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	orderStatus: [
		{ label: t("待支付"), value: 0 },
		{ label: t("已支付"), value: 1 },
		{ label: t("已完成"), value: 2 },
		{ label: t("已取消"), value: 3 },
	],
});
// cl-upsert
const Upsert = useUpsert({
	items: [
		// {
		// 	label: t("选择学员"),
		// 	prop: "studentId",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// 	required: true,
		// },
		// {
		// 	label: t("选择学员"),
		// 	prop: "studentId",
		// 	component: { vm: StudentSelect},
		// 	span: 12,
		// 	required: true,
		// },

		// {
		// 	label: t("选择商品"),
		// 	prop: "productIds",
		// 	value: [],
		// 	component: { vm: ProductSelect },
		// 	span: 12,
		// 	required: true,
		// },

		{
			label: t("总金额"),
			prop: "totalAmount",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,

		},
		{
			label: t("优惠金额"),
			prop: "discountAmount",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,

		},
		{
			label: t("订单状态"),
			prop: "orderStatus",
			component: { name: "el-radio-group", options: options.orderStatus },
			value: 0,
			required: true,
		},
		// {
		// 	label: t("支付时间"),
		// 	prop: "payTime",
		// 	component: {
		// 		name: "el-date-picker",
		// 		props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" },
		// 	},
		// 	span: 12,
		// },
	],
});

// cl-table
const Table = useTable({
	columns: [
		{ label: t("#"), type: "index" },
		{ label: t("学员ID"), prop: "studentId", minWidth: 140 },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.order.order,
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
